#include "praticleManager.h"
#include "point.h"

praticleManager* praticleManager::_instance = NULL;

praticleManager* praticleManager::Instance()
{
	if (_instance == NULL)
	{
		_instance = new praticleManager();
	}
	return _instance;
}

praticleManager::praticleManager()
{
	for (int i = 0; i < 1000; i++)
	{
		freeMem.push_back(new stdParticle());
	}
}

void praticleManager::updata()
{
	for (list<stdParticle*>::iterator itor = usingMem.begin();
		itor != usingMem.end();)
	{
		if ((*itor)->check_remove())
		{
			(*itor)->reset();
			freeMem.splice(freeMem.begin(), usingMem, itor);
		}else
		{
			(*itor)->updata();
			itor++;
		}
	}
}

void praticleManager::draw()
{
	for (list<stdParticle*>::iterator itor = usingMem.begin();
		itor != usingMem.end(); itor++)
	{
		(*itor)->draw();
	}
}

void praticleManager::add(int num, int t, float s, Point p)
{
	list<stdParticle*>::iterator itor = freeMem.begin();
//	(*itor)->setInformation(num, t, s, p, 0);
	usingMem.splice(usingMem.begin(), freeMem, itor);
}

void praticleManager::clear()
{
	freeMem.splice(freeMem.begin(), usingMem);
}